package com.haojiang.mh.ui.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter

/**
 * ViewPager+Fragment适配器
 *
 * Created by ZapFive on 2019-05-25.
 *
 * wuzhuang@mirahome.me
 */
class MainPagerAdapter(fm: FragmentManager, private val fragmentList: List<Fragment>,
                       private val titleList: List<String>? = null) : FragmentPagerAdapter(fm) {

    override fun getItem(position: Int): Fragment {
        return fragmentList[position]
    }

    override fun getCount(): Int {
        return if (fragmentList.isNullOrEmpty()) {
            0
        } else {
            fragmentList.size
        }
    }

    override fun getPageTitle(position: Int): CharSequence? {
        return if (titleList.isNullOrEmpty()) {
            super.getPageTitle(position)
        } else {
            titleList[position]
        }
    }
}
